#include "pica_common.h"
#include <pica_lcmgr_client.hh>
#include <pica_port_map.hh>

#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <ctype_pica_lcmgr_api.h>
#ifdef __cplusplus
}
#endif

extern bool pica_get_cosq_stat_counter(const usp_t& usp,
        int cosq, const cosq_stat_type_t type, uint64_t& counter);
extern bool pica_get_port_stat_counter(const usp_t& usp,
        const stat_type_t type, uint64_t& counter);

bool pica_get_port_name(usp_t usp, char *portName)
{
    /* in C++ world */
    string ifname;
    int len, i;

    //index_to_usp(port,usp);
    usp_to_ifname(ifname, usp);
    len = ifname.size();
    for (i=0; i<=len; i++) {
         portName[i] = ifname[i];
    }
    portName[i] = '\0';

    return true;
}

bool pica_get_port_counter(usp_t usp,
        const stat_type_t type, uint64_t *counterValue)
{
    bool rc;
    uint64_t value = 0;

    //index_to_usp(port,usp);
    rc = pica_get_port_stat_counter(usp, type, value);
    if (!rc) {
        *counterValue = 0;
        return false;
    } else {
        *counterValue = value;
        return true;
    }
}

bool pica_get_port_cosq_counter(usp_t usp, int cosq,
        const cosq_stat_type_t type, uint64_t *counterValue)
{
    bool rc;
    uint64_t value = 0;

    //index_to_usp(port,usp);
    rc = pica_get_cosq_stat_counter(usp, cosq, type, value);
    if (!rc) {
        *counterValue = 0;
        return false;
    } else {
        *counterValue = value;
        return true;
    }
}
